package admin.models;

import helpers.GeneralHelper;

import java.util.Collections;

import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheManager;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyOpts;
import com.googlecode.objectify.ObjectifyService;

import entities.Page;

public class PageModel {
	private Objectify ofy;
	
	private Cache cache = null;
	
	private String prefix = "";

	private static PageModel instance = null;
	
	public static PageModel getInstance() {
		if (instance == null) {
			instance = new PageModel();
		}
		
		return instance;
	}
	
	private PageModel() {
		try {
			ObjectifyService.register(Page.class);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		cache = GeneralHelper.getCache();
		ofy = GeneralHelper.getObjectify();
	}
	
	public Page getPage(String id) {
		Page page = new Page();
		try {
			page = ofy.get(new Key<Page>(Page.class, id));
		} catch (Exception e) {
			page = null;
		}
		return page;
	}
	
	public void insert(Page page) {
		ofy.put(page);
	}
	
	public void delete(Page page) {
		ofy.delete(page);
	}
}
